-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add capability to write signal with unique samps_per_frame
to wfdb.io.wrsamp
#510
base: main
Are you sure you want to change the base?
Conversation
if p_signal is not None and d_signal is not None: | ||
signal_list = [p_signal, d_signal, e_p_signal, e_d_signal] | ||
signals_set = sum(1 for var in signal_list if var is not None) | ||
if signals_set != 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentionally changing behavior for calls where p_signal=None
and d_signal=None
? In the past, this would evaluate to False when e_p_signal=None
and e_d_signal=None
, but it now evaluates to True.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tompollard , if all signals are passed as None a failure will occur further down the line. @bemoody , do we want to allow all signals to be None when calling wfdb.io.wrsamp
? If we don't want to allow that then I will leave the code as I have it which requires that one of the signals is set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If passing None
for both signals (p_signal
and d_signal
) previously resulted in an error, then the new behavior is an improvement. Unless people were intentioanlly calling the function with both signals set to None previously, this change isn't a problem.
wfdb/io/record.py
Outdated
# required features. | ||
|
||
# If samps_per_frame is a list, check that it aligns as expected with the channels in the signal | ||
if len(samps_per_frame) > 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If samps_per_frame
is not a list (e.g. it's an int
), this will error out.
len(4)
TypeError: object of type 'int' has no len()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
wfdb/io/record.py
Outdated
raise TypeError("Unsupported signal format. Must be ndarray or list of lists.") | ||
|
||
# Check that the number of channels matches the number of samps_per_frame entries | ||
if num_sig_channels != len(samps_per_frame): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above, len(samps_per_frame)
will error if samps_per_frame
is an int.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
866fe10
to
def62e9
Compare
@tompollard , if this failing test is of concern, could you guide me on what to do to resolve it:
|
It looks like the style checks are failing (https://github.com/MIT-LCP/wfdb-python/actions/runs/11408864264/job/31747939807?pr=510). To fix, you'll need to make sure that the code conforms to black (install black, run black over the code to reformat). |
The following raises an error:
In this case, wrsamp should raise an exception to say that if |
The following raises an error:
The problem here is that I think it should be straightforward to restructure |
@bemoody , thanks for catching this. I think this also applies for I've also updated the check to make sure Finally, I think we should allow passing
Please let me know if you disagree, or have other thoughts with respect to this case. |
|
This PR adds the capability for writing signals with unique samples per frame (
samps_per_frame
) towfdb.io.wrsamp
. This is typically the function that is used to write WFDB files. This was previously only possible to do by creating a Record first and using itswrsamp
method to do the write.@bemoody , I do feel like checking that the frames were uniform took a bit of extra code. I'm happy to leave it like this but also open to discussing other approaches.
I've added a couple of tests to check that this continues to work as expected.